﻿using ACCPS1ProjectDemo.ControlDemo;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace ACCPS1ProjectDemo
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            //右下角显示的日期
            tslblDate.Text = GetDayAndWeek();
            
           
        }
        #region 自定义方法

        private void LoadUserControl(UserControl uc)
        {
            uc.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(uc);
        }



        /// <summary>
        /// 获取当前日期和星期
        /// </summary>
        /// <returns></returns>
        public string GetDayAndWeek()
        {
            string week = "";
            switch(DateTime.Now.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    week = "星期一";
                    break;
                case DayOfWeek.Tuesday:
                    week = "星期二";
                    break;
                case DayOfWeek.Thursday:
                    week = "星期三";
                    break;
                case DayOfWeek.Wednesday:
                    week = "星期四";
                    break;
                case DayOfWeek.Friday:
                    week = "星期五";
                    break;
                case DayOfWeek.Saturday:
                    week = "星期六";
                    break;
                case DayOfWeek.Sunday:
                    week = "星期日";
                    break;
            }
            return DateTime.Now.ToString("yyyy年MM月dd日 " + week);
        }
        #endregion

        #region 窗体事件
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("确定要退出应用程序吗？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result!=DialogResult.OK)
            {
                e.Cancel = true;
            }
        }

        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }
        #endregion

        #region 左部按钮事件
        /// <summary>
        /// 在右部打开一个窗口
        /// </summary>
        private void tabBtn1_1_Click(object sender, EventArgs e)
        {
            //将面板中的所有控件移除
            splitContainer1.Panel2.Controls.Clear();  //Controls属性：容器中的控件集合
            //创建用户控件对象
            SimpleUC uc = new SimpleUC();
            //设置用户控件占满这个面板
            uc.Dock = DockStyle.Fill;
            //将用户控件加入面板中
            splitContainer1.Panel2.Controls.Add(uc);
        }
        #endregion

        //返回起始页
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //将面板中的所有控件移除
            splitContainer1.Panel2.Controls.Clear();  //Controls属性：容器中的控件集合
            //创建用户控件对象
            StartUc uc = new StartUc();
            //设置用户控件占满这个面板
            uc.Dock = DockStyle.Fill;
            //将用户控件加入面板中
            splitContainer1.Panel2.Controls.Add(uc);
        }

        //DateTimePicker(时间日期)
        private void tsbtnDateTimePicker_Click(object sender, EventArgs e)
        {
            DateTimePickerDemo uc = new DateTimePickerDemo();
            uc.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(uc);
            
        }
        /// <summary>
        /// ListView(列表）
        /// </summary>
        private void listViewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewDemo uc = new ListViewDemo();
            uc.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(uc);
            
        }

        /// <summary>
        /// 当Panel中的控件添加之后，显示对应的文件
        /// </summary>
        private void splitContainer1_Panel2_ControlAdded(object sender, ControlEventArgs e)
        {
            toolStripLabel2.Text = e.Control.GetType().ToString() + ".cs";
        }

        /// <summary>
        /// DataGridView控件
        /// </summary>
        private void dataGridViewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewDemo uc = new DataGridViewDemo();
            LoadUserControl(uc);
        }

        /// <summary>
        /// Chart（图表）控件
        /// </summary>
        private void ChartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadUserControl(new ChartDemo());
        }
    }
}
